#include "Window.h"

#include <cassert>
#include <exception>

Win32::WindowClassType<Window, &Window::WndProc> Window::m_WCT("windowclassname", 0, 0, 0, 0);

Window::Window(const std::string& title, int width, int height)
	: m_Title(title), m_Width(width), m_Height(height)
{
	assert(m_Width > 0);
	assert(m_Height > 0);

	// create the window
	m_Handle = m_WCT.createWindow(*this, 0, m_Title.c_str(), WS_OVERLAPPEDWINDOW, m_Width, m_Height);

	if (m_Handle == INVALID_HANDLE_VALUE)
		throw std::runtime_error("[Error] Create Window failed!");

	ShowWindow(m_Handle, 1);
}

const std::string& Window::GetTile() const
{
	return m_Title;
}

int Window::GetWidth() const
{
	return m_Width;
}

int Window::GetHeight() const
{
	return m_Height;
}

HWND Window::GetHandle() const
{
	return m_Handle;
}

LRESULT Window::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_KEYDOWN:
		break;
	case WM_KEYUP:
		break;
	case WM_CLOSE:
		DestroyWindow(m_Handle);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_MOUSEMOVE:
		break;
	default:
		return DefWindowProc(m_Handle, msg, wParam, lParam);
	}

	return 0;
}